
<h1><span class="yiyi-st" id="yiyi-12">numpy.random.randn</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randn.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randn.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.random.randn"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.random.</code><code class="descname">randn</code><span class="sig-paren">(</span><em>d0</em>, <em>d1</em>, <em>...</em>, <em>dn</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">从“标准正态”分布返回样本（或样本）。</span></p>
<p><span class="yiyi-st" id="yiyi-15">If positive, int_like or int-convertible arguments are provided, <a class="reference internal" href="#numpy.random.randn" title="numpy.random.randn"><code class="xref py py-obj docutils literal"><span class="pre">randn</span></code></a> generates an array of shape <code class="docutils literal"><span class="pre">(d0,</span> <span class="pre">d1,</span> <span class="pre">...,</span> <span class="pre">dn)</span></code>, filled with random floats sampled from a univariate “normal” (Gaussian) distribution of mean 0 and variance 1 (if any of the <img alt="d_i" class="math" src="../../_images/math/ae410da349d05c4fb338df88cd9a205e562e4701.png" style="vertical-align: -2px"> are floats, they are first converted to integers by truncation). </span><span class="yiyi-st" id="yiyi-16">如果没有提供参数，则返回从分布中随机抽取的单个浮点数。</span></p>
<p><span class="yiyi-st" id="yiyi-17">这是一个方便的功能。</span><span class="yiyi-st" id="yiyi-18">如果你想要一个以元组作为第一个参数的接口，请改用<a class="reference internal" href="numpy.random.standard_normal.html#numpy.random.standard_normal" title="numpy.random.standard_normal"><code class="xref py py-obj docutils literal"><span class="pre">numpy.random.standard_normal</span></code></a>。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-19">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-20"><strong>d0，d1，...，dn</strong>：int，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-21">返回的数组的尺寸应该都是正数。</span><span class="yiyi-st" id="yiyi-22">如果没有给出参数，则返回单个Python浮动。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-23">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-24"><strong>Z</strong>：ndarray或float</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-25">A <code class="docutils literal"><span class="pre">（d0，</span> <span class="pre">d1，</span> <span class="pre">...，</span> <span class="pre">dn）</span>的来自标准正态分布的浮点样本，或者如果没有提供参数，则使用单个这样的浮点。</code></span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-26">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-27"><code class="xref py py-obj docutils literal"><span class="pre">random.standard_normal</span></code></span></dt>
<dd><span class="yiyi-st" id="yiyi-28">类似，但是以元组为参数。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-29">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-30">对于<img alt="N(\mu, \sigma^2)" class="math" src="../../_images/math/93af1f49bf6bbf05f549f49609becdb5f7039538.png" style="vertical-align: -4px">的随机样本，使用：</span></p>
<p><span class="yiyi-st" id="yiyi-31"><code class="docutils literal"><span class="pre">sigma</span> <span class="pre">*</span> <span class="pre">np.random.randn（...）</span> <span class="pre">+</span> <span class="pre">t5&gt;</span></code></span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-32">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">()</span>
<span class="go">2.1923875335537315 #random</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-33">来自N（3，6.25）的2&#xD7;4数组样本：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mf">2.5</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="mi">3</span>
<span class="go">array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],  #random</span>
<span class="go">       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]]) #random</span>
</pre></div>
</div>
</dd></dl>
